<?php

namespace app\modules\setting\models\auth;

use yii\helpers\Json;

/**
 * This is the model class for table "{{%etc_office_video_upload}}".
 *
 * @property int $id
 * @property string $code etc_user_tiktok_product_selected.code
 * @property int $selected_id etc_user_tiktok_product_selected.id
 * @property int $user_id 机构id，sys_adminuser.id
 * @property int $tiktok_id tiktok账号，etc_office_tiktok_account.id
 * @property string $video_link 视频链接
 * @property string $video_ad_code 广告投流码
 * @property string $video_time 视频发布时间
 * @property int $status 0未投放，1已投放
 */
class EtcOfficeVideoUpload extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%etc_office_video_upload}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['code', 'selected_id', 'user_id', 'tiktok_id', 'video_link', 'video_ad_code', 'video_time', 'status'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            
            'id' => 'ID',
            
            'code' => 'etc_user_tiktok_product_selected.code',
            
            'selected_id' => 'etc_user_tiktok_product_selected.id',
            
            'user_id' => '机构id，sys_adminuser.id',
            
            'tiktok_id' => 'tiktok账号，etc_office_tiktok_account.id',
            
            'video_link' => '视频链接',
            
            'video_ad_code' => '广告投流码',
            
            'video_time' => '视频发布时间',
            
            'status' => '0未投放，1已投放',
        ];
    }


    public function beforeValidate()
    {
        foreach ($this->attributes() as $field){
            if (is_array($this->$field)){
                $this->$field = Json::encode($this->$field);
            }
        }

        return parent::beforeValidate(); // TODO: Change the autogenerated stub
    }

    public function getFirstErrorStr()
    {
        $errors = $this->getErrors();

        if ($errors){
            foreach ($errors as $item){
                return $item[0];
            }
        }

        return "";
    }
}
